<template>
	<view class="comment-list-page">
		<view v-for="(comment, index) in commentList" :key="index" class="comment-item">
			<!-- 左侧用户信息和评论内容 -->
			<view class="left-content">
				<view class="user-info">
					<image :src="hname+comment.avatar" class="avatar" mode="aspectFill"></image>
					<text class="nickname">{{ comment.username }}</text>
				</view>
				<text class="comment-text">{{ comment.content }}</text>
				<text class="publish-time">{{ comment.createdAt }}</text>
			</view>
			<!-- 右侧话题图片 -->
			<view class="right-image" @click="viewTopicDetail(comment.topicId)">
				<image :src="hname+comment.mediaUrl" class="topic-image" mode="aspectFill"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseUrl,
		getMyComment
	} from "@/api/index.js"
	export default {
		data() {
			return {
				hname: baseUrl,
				userInfo: {},
				// 模拟评论列表数据
				commentList: []
			};
		},
		async onLoad() {
			let uInfo = uni.getStorageSync('mini-userinfo')
			if (uInfo) {
				this.userInfo = uInfo
			}
			const res = await getMyComment(this.userInfo.id)
			this.commentList=res.data.data
			console.log(res, '????????????');
		},
		methods:{
			viewTopicDetail(id) {
				// const params = encodeURIComponent(JSON.stringify(topic));
				uni.navigateTo({
					url:`/pages/community/detail?topicId=${id}`
				})
			},
		}
	}
</script>

<style lang="scss">
	.comment-list-page {
		padding: 20rpx;
	}

	.comment-item {
		display: flex;
		margin-bottom: 30rpx;
		padding: 20rpx;
		border-bottom: 1rpx solid #eee;
	}

	.left-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		margin-right: 20rpx;
	}

	.user-info {
		display: flex;
		align-items: center;
		margin-bottom: 15rpx;
	}

	.avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		margin-right: 15rpx;
	}

	.nickname {
		font-size: 28rpx;
		color: #333;
	}

	.comment-text {
		font-size: 26rpx;
		color: #666;
		margin-bottom: 10rpx;
	}

	.publish-time {
		font-size: 24rpx;
		color: #999;
	}

	.right-image {
		width: 160rpx;
		height: 160rpx;
	}

	.topic-image {
		width: 100%;
		height: 100%;
		border-radius: 8rpx;
	}
</style>